<?php
namespace app\index\controller;

use think\Db;
use think\Request;
use app\index\model\Sms;
use app\index\model\User;
use think\Cookie;
class Api extends \think\Controller
{


    public function sms()
    {

        // $tom  = '18210787405'; 
        header("content-type:text/html; charset=utf-8"); 
        $tom  = input('s');
        $rand = rand(1000,9999);
        $cha  = 'http://api.chanyoo.cn/utf8/interface/send_sms.aspx?username=guomengtao1&password=aa77bb&content=验证码：'.$rand.'【高血压】&receiver='.$tom ;
        $fp = file_get_contents($cha);
         //转xml为数组形式
        $xml = simplexml_load_string($fp);
        $data = json_decode(json_encode($xml),TRUE);
        echo $data['message'];
        if ($data['message']='短信提交成功') {
        // if ($data['result']>=0) {
            // 存入短信发送日志表
               $user        = Sms::create([
                'phone'   =>  $tom,
                'rand'       =>  $rand
            ]);

        }

    }





}
 